package com.wld.blacklist.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wld.blacklist.mapper.DetailsMapper;
import com.wld.blacklist.dao.entity.Comment;
import com.wld.blacklist.service.DetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class DetailsServiceImpl extends ServiceImpl<DetailsMapper, Comment> implements DetailsService {
    private DetailsMapper detailsMapper;

    @Autowired
    public DetailsServiceImpl(DetailsMapper detailsMapper){
        this.detailsMapper = detailsMapper;
    }

    /**
     * 根据文章主键id查对应的评论信息
     *
     * @param id 文章主键
     * @return 评论信息
     */
    @Override public List<Comment> query(Integer id) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("article_id",id);
        queryWrapper.orderByDesc("insert_time");
        return detailsMapper.selectList(queryWrapper);
    }
}
